package cn.yunhe.controller;

import cn.yunhe.model.Role;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zs on 2017/12/18.
 */
@Controller
@RequestMapping("/params")
public class ParamsController {

    @RequestMapping("/getParams")
    public ModelAndView getParams(@RequestBody Role role) {
        System.out.println("角色名" + role.getRoleName());
        System.out.println("开始位置：" + role.getPageParams().getStart() + ",取到:" + role.getPageParams().getLimit());

        List<Role> list = new ArrayList<Role>();

        Role role1 = new Role(1, "张三", "admin");
        Role role2 = new Role(2, "李四", "customer");
        Role role3 = new Role(3, "王五", "coder");

        list.add(role1);
        list.add(role2);
        list.add(role3);

        ModelAndView mv = new ModelAndView();
        mv.setView(new MappingJackson2JsonView());
        mv.addObject("list", list);

        return mv;
    }

    @RequestMapping("/deleteRole")
    public ModelAndView deleteRole(@RequestBody List<Integer> list) {
        System.out.println(list);
        //后台返回的受影响的行数
        int total = 3;

        ModelAndView mv = new ModelAndView();
        mv.setView(new MappingJackson2JsonView());
        mv.addObject("total", total);

        return mv;

    }

    @RequestMapping("/seriaParams")
    public ModelAndView seriaParams(Role role) {
        System.out.println("roleName====" + role.getRoleName());
        System.out.println("note==========" + role.getNote());
        ModelAndView mv = new ModelAndView();

        return mv;
    }


}
